]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
searchDisplay: Split renderResults()
authorFlorian Müllner <fmuellner@gnome.org>
Fri, 17 Feb 2012 18:39:25 +0000 (19:39 +0100)
committerFlorian Müllner <fmuellner@gnome.org>
Tue, 21 Feb 2012 22:00:53 +0000 (23:00 +0100)
renderResults() updates the results set, determines the number of
results to display, retrieves the corresponding result metas and
adds a new results actor for each meta.
Splitting the function in those parts allows to move the retrieval
of the result metas into SearchResults, which is where we ensure
flicker-free rendering and control the selection - we want to keep
both features for asynchronous result metas which we are about to
introduce.

https://bugzilla.gnome.org/show_bug.cgi?id=663125

js/ui/searchDisplay.js

index 85a0631502a3252f3fb91cf7df90a98d9cdc1221..8caf4330383c586dc333f9e7c19f50531dfbe34d 100644 (file)
@@ -115,37 +115,42 @@ const GridSearchResults = new Lang.Class({
         this.actor.connect('notify::width', Lang.bind(this, function() {
             this._width = this.actor.width;
             Meta.later_add(Meta.LaterType.BEFORE_REDRAW, Lang.bind(this, function() {
-                this._tryAddResults();
+                let results = this.getResultsForDisplay();
+                if (results.length == 0)
+                    return;
+
+                let metas = provider.getResultMetas(results);
+                this.renderResults(metas);
             }));
         }));
         this._notDisplayedResult = [];
         this._terms = [];
     },
 
-    _tryAddResults: function() {
+    getResultsForDisplay: function() {
         let canDisplay = this._grid.childrenInRow(this._width) * MAX_SEARCH_RESULTS_ROWS
                          - this._grid.visibleItemsCount();
 
         let numResults = Math.min(this._notDisplayedResult.length, canDisplay);
-        if (numResults == 0)
-            return;
-        let results = this._notDisplayedResult.splice(0, numResults);
-        let metas = this.provider.getResultMetas(results);
-        for (let i = 0; i < metas.length; i++) {
-            let display = new SearchResult(this.provider, metas[i], this._terms);
-            this._grid.addItem(display.actor);
-        }
+
+        return this._notDisplayedResult.splice(0, numResults);
     },
 
     getVisibleResultCount: function() {
         return this._grid.visibleItemsCount();
     },
 
-    renderResults: function(results, terms) {
+    setResults: function(results, terms) {
         // copy the lists
         this._notDisplayedResult = results.slice(0);
         this._terms = terms.slice(0);
-        this._tryAddResults();
+    },
+
+    renderResults: function(metas) {
+        for (let i = 0; i < metas.length; i++) {
+            let display = new SearchResult(this.provider, metas[i], this._terms);
+            this._grid.addItem(display.actor);
+        }
     },
 
     clear: function () {
@@ -350,7 +355,9 @@ const SearchResults = new Lang.Class({
         let meta = this._metaForProvider(provider);
         meta.resultDisplay.clear();
         meta.actor.show();
-        meta.resultDisplay.renderResults(results, terms);
+        meta.resultDisplay.setResults(providerResults, terms);
+        let displayResults = meta.resultDisplay.getResultsForDisplay();
+        meta.resultDisplay.renderResults(provider.getResultMetas(displayResults));
         return true;
     },
 
@@ -383,7 +390,9 @@ const SearchResults = new Lang.Class({
                 this._clearDisplayForProvider(i);
                 let meta = this._metaForProvider(provider);
                 meta.actor.show();
-                meta.resultDisplay.renderResults(providerResults, terms);
+                meta.resultDisplay.setResults(providerResults, terms);
+                let displayResults = meta.resultDisplay.getResultsForDisplay();
+                meta.resultDisplay.renderResults(provider.getResultMetas(displayResults));
             }
         }